<template>
  <div class="loginWrapper">
    <div class="contentWrapper">
      <h1 class="f-zhong" @click="do_goHome"><img src="../assets/login/minzi2019626.png" alt="">  <img src="../assets/login/lianjie2019626.png" alt=""></h1>
      <div class="content">
        <div class="contentLeft">

        </div>
        <div class="contentRight">
          <h5 @click="test">忘记密码</h5>
          <div class="inputGroup" v-for="(item,index) in inputList" :key="index">
            <span class="img"> <img :src="item.imgSrc" alt=""></span>
            <input :type="item.type" :placeholder="item.placeholder" v-model="inputList[index].model" :maxlength="item.maxLength">
            <button v-if="index==1" class="codeButton" @click="do_getCode" v-text="btntxt" :disabled="disabled" :style="{background:getCode==true?'grey':'#41bafe' }"></button>
          </div>
          <button class="reset" @click="def_reset"> 重置</button>
          <div class="inputGroup"> <button class="regist" @click="do_regist"> 找回密码 </button></div>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "BS_cgkLogin",
    data(){
      return{
        inputList:[
          {imgSrc:this.$ZcPublic.Domain+'static/RSImg/phone (2).png',maxLength:'11',type:"text",placeholder:'请输入手机号',model:''},
          {imgSrc:this.$ZcPublic.Domain+'static/RSImg/yanzhengma.png',maxLength:'',type:"text",placeholder:'请输入验证码',model:''},
          {imgSrc:this.$ZcPublic.Domain+'static/RSImg/mima.png',maxLength:'',type:"password",placeholder:'请输入新密码',model:''},
          {imgSrc:this.$ZcPublic.Domain+'static/RSImg/mima.png',maxLength:'',type:"password",placeholder:'请确认新密码',model:''}
          // {imgSrc:'',type:"text",placeholder:'请输入初始密码',model:''},
        ],
        btntxt:'获取验证码',
        getCode:false,
        disabled:false
      }
    },
    methods:{
      do_goHome(){
        this.$router.push('/BS_cgkHome')
      },
      test(){

      },
      def_time() {
        this.getCode=true
        if (this.time > 0) {
          this.time--;
          this.btntxt=this.time+"s后重新获取";
          setTimeout(this.def_time, 1000);
        } else{
          this.time=0;
          this.btntxt="获取验证码";
          this.disabled=false;
          this.getCode=false
        }
      },
      do_help(){

      },
      do_getCode(){
        try {
          let me=this;
          let reg=11 && /^[1]([0-9])[0-9]{9}$/;
          if(me.inputList[0].model===''){
            this.$confirm({
              type:'温馨提示',
              msg:'请输入手机号！',
              btn:{
                ok:'ok'
              }
            })
          }else if(!reg.test(me.inputList[0].model)){
            this.$confirm({
              type:'温馨提示',
              msg:'手机号格式错误！',
              btn:{
                ok:'ok'
              }
            })
          } else{
            me.time=60;
            me.disabled=true;
            me.def_time();
            me.post_getCode()
          }
        }catch (e) {
          alert(e)
          // zcLogger.Log({
          //   Vue : 'zcPerson.vue',
          //   Fun : 'doAdd',
          //   Msg : e.message
          // });
        }
      },
      post_getCode(){
        let me=this
        me.$ZcPublic.zcServer.Post({//获取验证码
          IsNeedLogin: 'false',
          Paras: {
            Name: 'Vue_resultLib',
            action: "Ext_PhoneCode",
            Data: {
              OrganCode:"01",
              Telephone:me.inputList[0].model
            }
          },
          Callback:   me.cb_getCode,
          Scope: me,
        });

      },
      cb_getCode(resJson,scoped){
        console.log("验证码",resJson)
        if(!resJson.success){
          this.$confirm({
            type:'温馨提示',
            msg:resJson.msg,
            btn:{
              ok:'yes'
            }
          })
        }
      },
      def_reset(){
        this.inputList.forEach((item) => {
          item.model = ''
        })
        this.time = 0;
        this.btntxt = "获取验证码";
      },
      do_regist(){
        let me = this;
        if(me.inputList[2].model!= me.inputList[3].model){
          this.$confirm({
            type:'错误',
            msg:'两次密码不一致！',
            btn:{
              ok:'yes'
            }
          })
        }else {
          me.$ZcPublic.zcServer.Post({
            IsNeedLogin: 'false',
            Paras: {
              Name: 'Vue_resultLib',
              action: "Ext_ProjectLeaderChangePwd",
              data: {
                "Telephone": me.inputList[0].model,
                "Password": me.inputList[2].model,
                "VerifyCode": me.inputList[1].model
              }
            },
            Callback:  me.cb_do_regist,
            Scope: me,
          });
        }

      },
      cb_do_regist(resJson,scoped){
        console.log("找回密码",resJson)
        if(resJson.success){
          localStorage.removeItem('UserCode')
          this.$toast({
            icon:'ok',
            msg:'找回成功！'
          })
          let me =this
          setTimeout(()=>{
            me.$router.push({name:'BS_cgkLogin',query: {ver: new Date().getTime()}})
          },1600)
        }else {
          this.$confirm({
            type:'温馨提示',
            msg:resJson.msg,
            btn:{
              ok:"yes"
            }
        })
        }
      },
    }
  }
</script>

<style scoped>
  @import "../common/css/login-regist.css";
  *{
    margin: 0;
    padding: 0;
  }
</style>
